package com.gec.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gec.mapper.SysUserMapper;
import com.gec.model.system.SysMenu;
import com.gec.model.system.SysUser;
import com.gec.model.vo.RouterVo;
import com.gec.model.vo.SysUserQueryVo;
import com.gec.service.SysMenuService;
import com.gec.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    @Autowired
    private SysMenuService sysMenuService;

    /**分页查询*/
    @Override
    public IPage<SysUser> selectPage(IPage<SysUser> page, SysUserQueryVo userQueryVo) {
        IPage<SysUser> sysUserIPage = baseMapper.selectPage(page, userQueryVo);
        return sysUserIPage;
    }

    //根据userName查询数据
    @Override
    public SysUser getUserInfoUserName(String username) {
        QueryWrapper<SysUser> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username);
        SysUser sysUser = this.baseMapper.selectOne(queryWrapper);
        return sysUser;
    }
    //根据用户名称来获取用户信息
    @Override
    public Map<String, Object>  getUserInfo(String username) {
        Map<String,Object>map=new HashMap<>();
        SysUser sysUser = this.getUserInfoUserName(username);
        //根据用户id获取菜单权限值
        List<RouterVo> routerVoList=sysMenuService.findUserMenuList(sysUser.getId());
        //根据用户id获取用户按钮值
        List<String>permsList=sysMenuService.findUserPermList(sysUser.getId());
        map.put("roles","[admin]");
        map.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        map.put("name",sysUser.getName());
        map.put("buttons",permsList);
        map.put("routers",routerVoList);
        return map;
    }

}
